package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @ApiOperation(value = "新增床位信息", notes = "传入床位信息进行新增")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @PostMapping("/create")
    public ResponseResult saveBed(@RequestBody BedDto bedDto) {
        bedService.addBed(bedDto);
        return success();
    }

    @ApiOperation(value = "根据ID查询床位信息", notes = "传入床位ID进行查询")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = BedVo.class),
            @ApiResponse(code = 404, message = "床位不存在"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @GetMapping("/read/{id}")
    public ResponseResult readBed(@PathVariable Long id) {
        BedVo bedVo = bedService.getBedById(id);
        return success(bedVo);
    }

    @ApiOperation(value = "修改床位信息", notes = "传入床位信息进行修改")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @PutMapping("/update")
    public ResponseResult updateBed(@RequestBody BedDto bedDto) {
        bedService.updateBed(bedDto);
        return success();
    }

    @ApiOperation(value = "根据ID删除床位信息", notes = "传入床位ID进行删除")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 404, message = "床位不存在"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteBed(@PathVariable Long id) {
        bedService.deleteBed(id);
        return success();
    }

    @ApiOperation(value = "根据房间ID查询床位信息", notes = "传入房间ID进行查询")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = BedVo.class, responseContainer = "List"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @GetMapping("/read/room/{roomId}")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }
}
